<style>
  .picImg {
    width: 40px;
    height: 40px;
  }
  .input-unit{
    position: relative;
    top: -32px;
    left: 304px;
  }
  .el-dialog{
      width:1100px;
  }
</style>
<template>
  <div class="app-container">
    <!--&lt;!&ndash; 查询和其他操作 &ndash;&gt;-->
    <div class="filter-container">

      <el-button class="filter-item" type="primary" icon="el-icon-edit"
                 @click="handleAdd">新增
      </el-button>
    </div>

    <!-- 查询结果 -->
    <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row>

      <el-table-column align="center" min-width="100" label="渠道编号" prop="channelNo"/>
      <el-table-column align="center" min-width="100" label="渠道名称" prop="channelName"/>
      <el-table-column align="center" min-width="100" label="渠道服务URL地址" prop="serverURL"/>
      <el-table-column align="center" min-width="100" label="类型" prop="type"/>
      <el-table-column align="center" min-width="100" label="银行联行号" prop="bankCode"/>
      <el-table-column align="center" min-width="100" label="银行名称" prop="bankName"/>
      <el-table-column align="center" min-width="100" label="每秒最大并发提交数" prop="PTS"/>
      <el-table-column align="center" min-width="100" label="开放类型" prop="openType"/>
      <el-table-column align="center" min-width="100" label="渠道类型" prop="channelType"/>
      <el-table-column align="center" min-width="100" label="状态" prop="status"/>
      <el-table-column align="center" min-width="100" label="备注" prop="remark"/>
      <el-table-column align="center" label="操作" width="150" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary" size="mini"
                     @click="handleEdit(scope.row)">编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      @pagination="getList"/>
    <!-- 分配订单对话框 -->
    <el-dialog :visible.sync="editDialogVisible" title="新增渠道">
      <el-form ref="editForm" :rules="editFormRules" :model="editForm" status-icon label-position="left"
               label-width="100px" style="width: 400px; margin-left:50px;">
        <el-form-item label="渠道编号" prop="channelNo">
          <el-input v-model="editForm.channelNo" placeholder="渠道编号"/>
        </el-form-item>
        <el-form-item label="渠道名称" prop="channelName">
          <el-input v-model="editForm.channelName" auto-complete="off" placeholder="渠道名称"/>
        </el-form-item>
        <el-form-item label="渠道服务URL地址" prop="serverURL">
          <el-input v-model="editForm.serverURL" auto-complete="off" placeholder="渠道服务URL地址"/>
        </el-form-item>
        <el-form-item label="类型" prop="type">
            <el-radio v-model="editForm.type" label="0">银企直连</el-radio>
            <el-radio v-model="editForm.type" label="1">第三方机构</el-radio>
        </el-form-item>
        <el-form-item label="银行联行号" prop="bankCode">
            <el-input v-model="editForm.bankCode" auto-complete="off" placeholder="银行联行号"/>
        </el-form-item>
        <el-form-item label="每秒最大请求并发数" prop="PTS">
            <el-input v-model="editForm.PTS" auto-complete="off" placeholder="每秒最大请求并发数"/>
        </el-form-item>
        <el-form-item label="业务类型" prop="businessType">
            <el-radio v-model="editForm.businessType" auto-complete="off" label="1">代收</el-radio>
            <el-radio v-model="editForm.businessType" auto-complete="off" label="2">代付</el-radio>
            <el-radio v-model="editForm.businessType" auto-complete="off" label="3">代收+代付</el-radio>
        </el-form-item>
        <el-form-item label="业务子类型" prop="subBusiness">
          <el-radio v-model="editForm.subBusiness" auto-complete="off" label="1">对公</el-radio>
          <el-radio v-model="editForm.subBusiness" auto-complete="off" label="2">对私</el-radio>
          <el-radio v-model="editForm.subBusiness" auto-complete="off" label="3">对公+对私</el-radio>
        </el-form-item>
        <el-form-item label="开放类型" prop="openType">
          <el-radio v-model="editForm.openType" auto-complete="off" label="0">全年</el-radio>
          <el-radio v-model="editForm.openType" auto-complete="off" label="1">工作日</el-radio>
          <el-radio v-model="editForm.openType" auto-complete="off" label="2">周末</el-radio>
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <!-- <el-input v-model="editForm.startTime" auto-complete="off" placeholder="开始时间"/> -->
          <el-date-picker v-model="editForm.startTime" type="date" placeholder="开始时间" value-format="yyyy-MM-dd HH:MM:SS"></el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <!-- <el-input v-model="editForm.endTime" auto-complete="off" placeholder="结束时间"/> -->
          <el-date-picker v-model="editForm.endTime" type="date" placeholder="结束时间" value-format="yyyy-MM-dd HH:MM:SS"></el-date-picker>
        </el-form-item>  
        <el-form-item label="交易最小限额" prop="minMoney">
          <el-input v-model="editForm.minMoney" auto-complete="off" placeholder="交易最小限额"/>
          <span class="input-unit">元</span>
        </el-form-item>             
      </el-form>
      <el-form ref="editForm" :rules="editFormRules" :model="editForm" status-icon label-position="left"
               label-width="100px" style="width: 400px; margin-right: 59px; float: right; position: relative; bottom: 805px;">
            
            <el-form-item label="交易最大限额" prop="maxMoney">
              <el-input v-model="editForm.maxMoney" auto-complete="off" placeholder="交易最大限额"/>
            </el-form-item>
            <el-form-item label="当日累计最大交易金额" prop="dayMaxMoney">
              <el-input v-model="editForm.dayMaxMoney" auto-complete="off" placeholder="当日累计最大交易金额"/>
            </el-form-item> 
            <el-form-item label="当日累计最大交易笔数" prop="dayMaxTimes">
              <el-input v-model="editForm.dayMaxTimes" auto-complete="off" placeholder="当日累计最大交易笔数"/>
            </el-form-item>
            <el-form-item label="渠道优先级" prop="level">
              <el-input v-model="editForm.level" auto-complete="off" placeholder="渠道优先级"/>
            </el-form-item>
            <el-form-item label="费用计算方式" prop="calcType">
              <el-radio v-model="editForm.calcType" auto-complete="off" label="0">四舍五入</el-radio>
              <el-radio v-model="editForm.calcType" auto-complete="off" label="1">向下取整</el-radio>
              <el-radio v-model="editForm.calcType" auto-complete="off" label="2">向上取整</el-radio>
            </el-form-item>
            <el-form-item label="渠道类型" prop="channelType">
              <el-radio v-model="editForm.channelType" auto-complete="off" label="0">代付渠道</el-radio>
              <el-radio v-model="editForm.channelType" auto-complete="off" label="1">专用渠道</el-radio>
            </el-form-item>
            <el-form-item label="状态" prop="status">
              <el-radio v-model="editForm.status" auto-complete="off" label="0">正常</el-radio>
              <el-radio v-model="editForm.status" auto-complete="off" label="1">禁用</el-radio>
            </el-form-item>
            <el-form-item label="访问代码" prop="code">
              <el-input v-model="editForm.code" auto-complete="off" placeholder="访问代码"/>
            </el-form-item>
            <el-form-item label="访问秘钥" prop="secrit">
              <el-input v-model="editForm.secrit" auto-complete="off" placeholder="访问秘钥"/>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="editForm.remark" auto-complete="off" placeholder="备注"/>
            </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="doEdit">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { doGet, doPost } from '@/api'
  import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  import checkPermission from '@/utils/permission' // 权限判断函数
  export default {
    name: 'bank',
    components: { Pagination },
    filters: {},
    data() {
      return {
        pickerOptions1: {
            disabledDate(time) {
                return time.getTime() > Date.now();
            },
            shortcuts: [{
                text: '今天',
                    onClick(picker) {
                        picker.$emit('pick', new Date());
                    }
            }]
        },
        list: [],
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
        },
        editForm: {
          channelNo: undefined,
          channelName: undefined,
          serverURL: undefined,
          bankCode: undefined
        },
        editFormRules: {
          channelNo: [{ required: true, message: '渠道编号不允许为空', trigger: 'blur' }],
          channelName: [{ required: true, message: '渠道名称不允许为空', trigger: 'blur' }],
          serverURL: [{ required: true, message: '渠道服务URL地址不允许为空', trigger: 'blur' }],
          bankCode: [{ required: true, message: '银行联行号不允许为空', trigger: 'blur' }]
        },
        editDialogVisible: false
      }
    },
    created() {
      this.getList()
    },
    methods: {
      checkPermission,
      getList() {
        this.listLoading = true
        doGet('channel.html?op=channellist', this.listQuery).then(response => {
          this.list = response.rows
          this.total = response.rows.length
          this.listLoading = false
        }).catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
      },
      handleAdd() {
        this.editForm.bankName = undefined
        this.editForm.bankCode = undefined
        this.editDialogVisible = true
        this.dialogStatus = "create"
        this.editDialogVisible = true
        this.$nextTick(() => {
            this.$refs['dataForm'].clearValidate()
        })
      },
      handleEdit(row) {
          this.editForm = Object.assign({}, row);
          this.editIndex=this.list.indexOf(row);
          this.dialogStatus = "update"
          this.editDialogVisible = true
          this.$nextTick(() => {
              this.$refs['dataForm'].clearValidate()
          })
      },
      doEdit() {
        this.$refs['editForm'].validate(valid => {
          if (valid) {
            doGet('channel.html?op=addchannel', this.editForm)
              .then(response => {
                this.getList()
                this.editDialogVisible = false
                this.$notify.success({
                  title: '成功',
                  message: '添加成功'
                })
              })
              .catch(response => {
                this.$notify.error({
                  title: '失败',
                  message: response.message
                })
              })
          }
        })
      },
      doDelete(row) {
        doGet("channel.html?op=chgchannel",row)
          .then(response => {
            this.$notify.success({
              title: '成功',
              message: '删除银行成功'
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
          })
          .catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.message
            })
          })
      }
    }
  }
</script>
